<template>
	<view class="">
		<!-- commontext -->
		<view class="main_title">
			企业信息
		</view>
		<view class="form_box">
			<view class="input_block flex justify align">
				<view class="input_title">
					企业名称
				</view>
				<view class="input_text">
					<input type="text" v-model="form.enterprise_name" placeholder="填写企业名称"/>
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					企业类型
				</view>
				<view class="input_text flex align flex_right">
					<picker @change="bindPickerType" :value="typeInd" :range="typeArr">
						<view class="uni-input">{{typeArr[typeInd]}}</view>
						<view class="" v-if="typeInd == -1">
							请选择企业类型
						</view>
					</picker>
					<image class="right" src="../../static/icon/right2.png" mode="aspectFill"></image>
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					涉及专业
				</view>
				<view class="input_text flex align flex_right" @tap="toList">
					<text>{{workName}}</text>
					<image class="right" src="../../static/icon/right2.png" mode="aspectFill"></image>
				</view>
			</view>
			<view class="input_block flex justify align">
				<view class="input_title">
					主要负责人
				</view>
				<view class="input_text">
					<input type="text" v-model="form.person_charge" placeholder="填写主要负责人"/>
				</view>
			</view>
		</view>
		<view class="main_title">
			队伍介绍
		</view>
		<view class="form_box">
			<textarea v-model="form.introduce" name="" id="" cols="30" rows="10" placeholder="填入队伍介绍"></textarea>
		</view>
		
		<view class="btn" @tap="tosubmit">
			下一步
		</view>
	</view>

</template>

<script>
	const app = getApp()
	export default {
		data() {
			return {
				typeArr:['劳务班组','专业分包','技术团队'],
				typeInd: -1,
				form:{
					enterprise_name: "", //String	企业名称
					troops_ids: "", //企业类型，多个ID已英文字符逗号分割
					work_ids: "", //涉及专业，多个ID已英文字符逗号分割
					person_charge: "", //主要负责人
					introduce: "", //项目介绍
				},
				workName:'',
				workInd:'',
				id:null,
				isEdit:false
			}
		},
		onLoad(options) {
			if(options.id){
				this.isEdit = true
				this.id = options.id
				this.getInfo()
			}
		},
		onReady() {
			console.log('ready')
			if(this.isEdit){
				uni.setNavigationBarTitle({
					title:'修改企业名片'
				})
			}
			
		},
		onShow(){
			const _this = this
			uni.getStorage({
				key: 'work_name',
				success: function(res) {
					console.log(res.data, '缓存1--------------------');
					_this.workSelect = res.data
					let ids = []
					let  workName= []
					res.data.forEach(item=>{
						console.log(item)
						ids.push(item.uId)
						workName.push(item.two)
					})
					_this.workName = workName.join(',')
					_this.workInd = ids.join(',')
					_this.form.workName = workName.join(',')
					_this.form.work_ids = ids.join(',')
				}
			});
		},
		methods: {
			// 编辑获取信息
			getInfo(){
				uni.request({
					url: app.globalData.IP + 'addons/shopro/visiting_card/detail',
					data: {
						id:this.id
					},
					header: {
						token: app.globalData.token
					},
					method: 'GET',
					success: res => {
						console.log('修改项目',res)
						if(res.data.code == 1){
							let data = res.data.data
							this.form.introduce = data.introduce//	项目介绍
							this.form.troops_ids = data.troops_ids//队伍类型，多个ID已英文字符逗号分割
							this.typeInd = data.troops_ids == 200 ? 0 :data.troops_ids == 201?1:2
							this.form.work_ids = data.work_ids//专业/工种，多个ID已英文字符逗号分割
							this.workName = data.work_arr.join(',')
							this.workInd = data.work_ids
							this.form.enterprise_name = data.enterprise_name//String	企业名称
							this.form.person_charge=data.person_charge //主要负责人
						}else{
							uni.showToast({
								title: res.data.msg,
								icon:'none'
							})
							setTimeout(function(){
								uni.navigateBack({delta:1})
							},1000)
						}
					}
				})
			},
			// 
			bindPickerType(e){
				console.log(e)
				this.typeInd = e.detail.value
				this.form.troops_ids = e.detail.value == 0 ?'200':e.detail.value == 1?'201':'202'
			},
			
			toList(){
				uni.navigateTo({
					url: '/pages/typeSelection/typeSelection?pageurl=project'
				})
			},
			
			// 提交
			tosubmit(){
				if(!this.form.enterprise_name){
					uni.showToast({
						title: '请填入企业名称',
						icon:'none'
					})
					return 
				}
				if(!this.form.troops_ids){
					uni.showToast({
						title: '请选择企业类型',
						icon:'none'
					})
					return 
				}
				if(!this.form.work_ids){
					uni.showToast({
						title: '请选择涉及专业',
						icon:'none'
					})
					return 
				}
				if(!this.form.person_charge){
					uni.showToast({
						title: '请填入主要负责人',
						icon:'none'
					})
					return 
				}
				if(!this.form.introduce){
					uni.showToast({
						title: '请填入项目介绍',
						icon:'none'
					})
					return 
				}
				if(this.id){
					uni.navigateTo({
						url: '/pages/businessCardTwo/businessCardTwo?id='+this.id+'&obj='+JSON.stringify(this.form)
					})
				}else{
					uni.navigateTo({
						url: '/pages/businessCardTwo/businessCardTwo?obj='+JSON.stringify(this.form)
					})
				}
				
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #F7F7F7;
		padding: 30rpx 0;
	}
	.form_box{
		margin: 40rpx 28rpx;
		background-color: #fff;
		border-radius: 20rpx;
		padding: 20rpx 28rpx;
		.flex_right{
			justify-content: flex-end;
		}
	}
	.input_block{
		margin-bottom: 30rpx;
		image{
			width: 28rpx;
			height: 28rpx;
		}
	}
	.flex_right{
		justify-content: flex-end;
	}
	.input_block:last-child{
		margin-bottom: 0;
	}
	.input_title{
		color: #000;
		
	}
	.input_text{
		width: 78%;
		text-align: right;
	}
	.input_text .gray{
		
	}
	.input_text picker{
		width:78%
	}
	.main_title{
		font-size: 30rpx;
		color: #000;
		padding: 0 28rpx;
		font-weight: 600;
	}
	.btn{
		height: 110rpx;
		line-height: 110rpx;
		text-align: center;
		color: #fff;
		background: var(--base);
		border-radius: 15rpx;
		margin: 60rpx 160rpx 0;
	}
</style>
